package com.gec.system.controller;

import com.gec.system.util.OssTemplate;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Api(tags = "图片视频上传控制器")
@RequestMapping("admin/system/upload")
@CrossOrigin //解决跨域问题
public class UploadController {
    @Autowired
    private OssTemplate ossTemplate;

    //uploadImage
    @PostMapping("/uploadImage")
    public Result uploadImage(MultipartFile uploadImage) throws IOException{
        System.out.println("-----------------------------------------------");
        String imagePath = ossTemplate.upload(uploadImage.getOriginalFilename(), uploadImage.getInputStream());
        System.out.println("图片地址："+imagePath);
        return Result.ok(imagePath);

    }
}
